package org.grow.commodity.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @Author: xwg
 * @CreateDate: 21-8-9
 */
// 案例 已经不需要使用了
//@Component
public class CodeGeneratorEx {

//    @Autowired
    private ApplicationContext applicationContext;


//    private CodeGenerator codeGenerator;
    private ThreadLocal<CodeGenerator> codeGeneratorThreadLocal;
//    @PostConstruct
    public void init(){
        codeGeneratorThreadLocal=ThreadLocal
                .withInitial(()->applicationContext.getBean(CodeGenerator.class));
//        codeGenerator = applicationContext.getBean(CodeGenerator.class);
    }


    public String nextCode(String business){
//        String s = codeGenerator.nextCode(business);
        String s = codeGeneratorThreadLocal.get().nextCode(business);
        return s;
    }
}
